<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/filter/DateFilter.js"></script>
		
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		
        <script type="text/javascript">
        	var msMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.measurespecification');
			var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
			var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
			var ctStature = new i18nMessage('../../servlet/CodeTableServlet?name=CtStature');
			var ctCollar = new i18nMessage('../../servlet/CodeTableServlet?name=CtCollarType');
			var ctProductFamily = new i18nMessage('../../servlet/CodeTableServlet?name=CtProductFamily');
        	var store;
            var grid;
            
            var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/BiMeasureSpecificationServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			 Ext.onReady(function(){
                // create the Data Store
                
                
                store = new Ext.data.Store({
                    // load using HTTP
                    url: '../../servlet/BiMeasureSpecificationServlet?action=4',
                    
                    // the return will be XML, so lets set up a reader
                    reader: new Ext.data.XmlReader({
                        // records will have an "Item" tag
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [ // set up the fields mapping into the xml doc
                    // The first needs mapping, the others are very basic
                    'index', 'name', 'ctStature', 'ctStatureCode', 'ctCollarType','isAddItem','customerReference',
                     'biFranceCustomer', 'id', 'patronage', 'realPhoto1Name', 'realPhoto2Name', 'ctProductFamily', {
					 	name: 'biFranceCustomer.name',
					 	mapping: 'customerName'
					 }, {
					 	name: 'biFranceCustomer.department',
					 	mapping: 'customerDepartment'
					 }]),
                    
                    remoteSort: true
                });
                
                store.setDefaultSort('id', 'desc');
				
				var filters = new Ext.grid.GridFilters({
					  filters:[
					    {type: 'string',  dataIndex: 'name'},
						{type: 'string',  dataIndex: 'patronage'},
						{type: 'string',  dataIndex: 'customerReference'},
						{
						      type: 'list',  
						      dataIndex: 'ctStature', 
						      options: ctStature.getCtArray()
					    },
						{
						      type: 'list',  
						      dataIndex: 'ctCollarType', 
						      options: ctCollar.getCtArray()
					    },
						{type: 'string', dataIndex: 'biFranceCustomer.name'},
						{type: 'string', dataIndex: 'biFranceCustomer.department'}
					]});
                
                // create the grid
                grid = new Ext.grid.GridPanel({
                    title: msMessage.get('ui.measurespecification.listtitle'),
                    store: store,
					stripeRows: true,
					plugins: filters,
                    height: 560,
                    columns: [{
                        header: message.get('message.list.id'),
                        width: 20,
                        dataIndex: 'index',
                        sortable: false
                    }, 
//					{
//                        header: msMessage.get('ui.measurespecification.name'),
//                        width: 80,
//                        dataIndex: 'name',
//                        sortable: true
//                    }, 
//					{
//                        header: message.get('message.edit.productfamily'),
//                        dataIndex: 'ctProductFamily',
//                        sortable: true
//                    }, 
					{
                        header: msMessage.get('ui.measurespecification.stature'),
                        dataIndex: 'ctStature',
                        sortable: true
                    }, {
                        header: message.get('message.edit.collar'),
                        dataIndex: 'ctCollarType',
                        sortable: true
                    },{
                        header: msMessage.get('ui.measurespecification.patronage'),
                        dataIndex: 'patronage',
                        sortable: true
                    },{
                        header: message.get('message.edit.customerreference'),
                        dataIndex: 'customerReference',
                        sortable: true
                    },
//					{
//                        header: fcMessage.get('ui.francecustomer.name'),
//                        dataIndex: 'biFranceCustomer.name',
//                        sortable: true
//                    },{
//                        header: fcMessage.get('ui.francecustomer.department'),
//                        dataIndex: 'biFranceCustomer.department',
//                        sortable: true
//                    },
					{
                        header: message.get('message.list.eidtitem'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEditItem
                    },{
                        header: message.get('message.list.print'),
						width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderReport
                    },{
                        header: message.get('message.list.eidt'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEdit
                    },{
                        header: message.get('message.list.delete'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderDelete
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'biMeasureSpecification',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
                
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });
                
				function renderEditItem(value, p, record){
					if(record.data.isAddItem == 0){
						return String.format('<a href="measure_specification_item_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/sitemap_color.png" title="' + message.get('message.list.eidt') + message.get('message.list.eidtitem') + '" /><img width="10" src="../../images/icons/cross.png"></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
					}else{
						return String.format('<a href="measure_specification_item_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/sitemap_color.png" title="' + message.get('message.list.eidt') + message.get('message.list.eidtitem') + '" /><img width="10" src="../../images/icons/tick.png"></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
					}
					
				}
				
				function renderReport(value, p, record){
					return String.format('<a href="javascript: void(0);" target="_self"><img src="../../images/icons/printer.png" title="' + message.get('message.list.print') + '" onclick="window.open(\'../../servlet/PDFExportServlet?action=3&id={0}\');"/></a>', record.id);
				}
				
                function renderEdit(value, p, record){
                    return String.format('<a href="measure_specification_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
                }
                
                function renderDelete(value, p, record){
                    return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '"/></a>', record.id);
                }
                
                var detailWin;
				/*
                grid.on('rowdblclick', function(grid, rowIndex, e){
                    if (!detailWin) {
                        detailWin = new Ext.Window({
                            title: message.get('message.window.detail'),
                            layout: 'fit',
                            width: 800,
                            height: 650,
                            closeAction: 'hide',
                            plain: true,
                            items: [{
                                id: 'detailPanel',
                                region: 'center',
                                bodyStyle: {
                                    background: '#ffffff',
                                    padding: '7px'
                                },
                                html: message.get('message.window.empty')
                            }]
                        });
                    }
                    
                    detailWin.show(this);
                    var itemTplMarkup = [
						'<table cellspacing="0" id="the-table" style="width: 100%;"><tbody>',
							'<tr><td style="background:#eeeeee; width: 15%;">',
							message.get('message.list.id'),
							'</td><td>{id}</td>',
							'<td style="background:#eeeeee;width: 15%;">',
							msMessage.get('ui.measurespecification.patronage'),
							'</td><td>{patronage}</td></tr>',
							'<tr><td style="background:#eeeeee;">',
							msMessage.get('ui.measurespecification.stature'),
							'</td><td>{ctStature}</td>',
							'<td style="background:#eeeeee;">',
							message.get('message.edit.collar'),
							'</td><td>{ctCollarType}</td></tr>',
							'<tr><td style="background:#eeeeee;">',
							msMessage.get('ui.measurespecification.photo'),
							'</td><td><img id="customImg" height="200" src="../../_temp/{realPhoto1Name}"></td><td style="background:#eeeeee;">',
							msMessage.get('ui.measurespecification.photo'),
							'</td><td><img id="customImg" height="200" src="../../_temp/{realPhoto2Name}"></td></tr>',
						'</tbody></table><div id="itemList"></div>'
					];
                    var itemTpl = new Ext.Template(itemTplMarkup);
                    var detailPanel = Ext.getCmp('detailPanel');
                    itemTpl.overwrite(detailPanel.body, grid.getStore().getAt(rowIndex).data);
					
					var listStore = new Ext.data.Store({
	                    // load using HTTP
	                    url: '../../servlet/BiMeasureSpecificationServlet?action=100&id=' + grid.getStore().getAt(rowIndex).data.id,
	                    
	                    // the return will be XML, so lets set up a reader
	                    reader: new Ext.data.XmlReader({
	                        // records will have an "Item" tag
	                        record: 'item',
	                        id: 'id',
	                        totalRecords: 'itemTotal'
	                    }, [ 
	                    'index', 'number', 'designations', 
						'sizeXs','sizeS', 'sizeM', 'sizeL', 'sizeXl', 'sizeXxl', 'sizeXxxl','sizeXxxxl',
						'repeatS', 'repeatM', 'repeatL','repeatXl','repeatXxl','tolerance'])
	                }); 
					
					var listGrid = new Ext.grid.GridPanel({
	                    title: msMessage.get('ui.measurespecification.itemlisttitle'),
	                    store: listStore,
						stripeRows: true,
	                    height: 270,
	                    columns: [{
	                        header: message.get('message.list.id'),
	                        dataIndex: 'index'
	                    }, {
	                        header: msMessage.get('ui.measurespecification.itemnumber'),
	                        dataIndex: 'number'
	                    }, {
	                        header: msMessage.get('ui.measurespecification.itemdesignations'),
	                        dataIndex: 'designations'
	                    }, {
	                        header: 'XS',
	                        dataIndex: 'sizeXs'
	                    }, {
	                        header: 'S',
	                        dataIndex: 'sizeS'
	                    }, {
	                        header: 'M',
	                        dataIndex: 'sizeM'
	                    },{
	                        header: 'L',
	                        dataIndex: 'sizeL'
	                    },{
	                        header: 'XL',
	                        dataIndex: 'sizeXl'
	                    },{
	                        header: 'XXL',
	                        dataIndex: 'sizeXxl'
	                    },{
	                        header: 'XXXL',
	                        dataIndex: 'sizeXxxl'
	                    },{
	                        header: 'XXXXL',
	                        dataIndex: 'sizeXxxxl'
	                    },{
	                        header: msMessage.get('ui.measurespecification.tolerance'),
	                        dataIndex: 'tolerance',
							renderer: renderTolerance
	                    }],
	                    viewConfig: {
	                        forceFit: true
	                    },
	                    loadMask: true,
	                    renderTo: 'itemList'
	                });
					
					function renderTolerance(value, p, record){
						return String.format('(+/-){0}', value);
					}
					
					listStore.load();
					
					
	            });
	            */
            });
                    
                    
        </script>
    </head>
    <body>
        <div id="biMeasureSpecification">
        </div>
    </body>
</html>